﻿/**********************************************************
*
* 模块名称：WebDemo显示页面
* 当前版本：1.0
* 添加人员：楚涛
* 开始时间：2010-10-10
* 版本历史：v1.0
*
***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Database.Extend;
using LXChuTao.ECG.Demo.Entity;
using LXChuTao.ECG.Demo.WebUI;

public partial class Form_WebDemo : LXChuTao.ECG.Demo.WebUI.BasePage
{
    #region 私有变量
    /// <summary>
    /// 整数小计
    /// </summary>
    private int sumInt = 0;
    /// <summary>
    /// 正整数小计
    /// </summary>
    private int sumPositiveInt = 0;
    /// <summary>
    /// 负整数小计
    /// </summary>
    private int sumNegativeInt = 0;
    #endregion

    /// <summary>
    /// 页面载入
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                this.Response.CacheControl = "no-cache";
                this.BindGrid();
            }
            catch (Exception ex)
            {
                WebFunHelper.ShowMessage(this, "页面载入异常：" + ex.Message + "\nSQL：" + System.Database.DbCore.GetCurrentCommandText);
            }
        }
    }

    #region 页面事件
    /// <summary>
    /// GridView排序处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvResult_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (PreSortExpression != e.SortExpression)
        {
            PreSortExpression = e.SortExpression;
            IsAsc = true;
        }
        else
        {
            IsAsc = !IsAsc;
        }
        SetDataViewSortColumn(this.gvResult, IsAsc, e.SortExpression);
        this.BindGrid();
    }
    /// <summary>
    /// GridView行数据绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvResult_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow && e.Row.Cells.Count > 0)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#D9E0EF'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            string url = "WebDemoEdit.aspx?CMD=Edit&p_c_id=" + this.gvResult.DataKeys[e.Row.RowIndex][0].ToString();
            //鼠标样式
            e.Row.Attributes["style"] = "Cursor:hand";
            //单击修改
            //e.Row.Attributes.Add("title", "单击修改");
            //e.Row.Attributes.Add("onclick", "return Edit('" + url + "');");
            //双击修改
            e.Row.Attributes.Add("title", "双击修改");
            e.Row.Attributes.Add("ondblclick", "return Edit('" + url + "');");//双击修改
        }
        if (e.Row.RowIndex >= 0)
        {
            if (this.gvResult.DataKeys[e.Row.RowIndex]["C_INT"] != null
                && !string.IsNullOrEmpty(this.gvResult.DataKeys[e.Row.RowIndex]["C_INT"].ToString()))
            {
                sumInt += Convert.ToInt32(this.gvResult.DataKeys[e.Row.RowIndex]["C_INT"].ToString());
            }
            if (this.gvResult.DataKeys[e.Row.RowIndex]["C_INTA"] != null
                && !string.IsNullOrEmpty(this.gvResult.DataKeys[e.Row.RowIndex]["C_INTA"].ToString()))
            {
                sumPositiveInt += Convert.ToInt32(this.gvResult.DataKeys[e.Row.RowIndex]["C_INTA"].ToString());
            }
            if (this.gvResult.DataKeys[e.Row.RowIndex]["C_INTB"] != null
                && !string.IsNullOrEmpty(this.gvResult.DataKeys[e.Row.RowIndex]["C_INTB"].ToString()))
            {
                sumNegativeInt += Convert.ToInt32(this.gvResult.DataKeys[e.Row.RowIndex]["C_INTB"].ToString());
            }
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[9].Text = sumInt.ToString();
            e.Row.Cells[10].Text = sumPositiveInt.ToString();
            e.Row.Cells[11].Text = sumNegativeInt.ToString();
        }
    }
    /// <summary>
    /// 绑定页面数据事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnHidBindData_Click(object sender, EventArgs e)
    {
        this.BindGrid();
    }
    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            T_DEMOS entitys = new T_DEMOS();
            for (int i = 0; i < this.gvResult.Rows.Count; i++)
            {
                CheckBox chkBox = (CheckBox)this.gvResult.Rows[i].FindControl("chk");
                if (chkBox.Checked)
                {
                    T_DEMO entity = new T_DEMO();
                    entity.C_ID = this.gvResult.DataKeys[i][0].ToString();
                    entitys.Add(entity);
                }
            }
            if (entitys.Count > 0 && entitys.Delete() > 0)
            {
                BindGrid();
                WebFunHelper.ShowMessage(this, "删除成功！");
            }
        }
        catch (Exception ex)
        {
            WebFunHelper.ShowMessage(this, "删除异常：" + ex.Message);
        }
    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvResult.PageIndex = e.NewPageIndex;
        this.BindGrid();
    }
    #endregion

    #region 页面方法
    /// <summary>
    /// 绑定Grid信息
    /// </summary>
    private void BindGrid()
    {
        string strCol;
        OrderDirection orderDirect;
        if (string.IsNullOrEmpty(PreSortExpression))
            strCol = "C_EIDTDATE" ;
        else
            strCol = PreSortExpression;
        if (IsAsc)
            orderDirect = OrderDirection.Asc ;
        else
            orderDirect = OrderDirection.Desc ;
        this.gvResult.DataSource = new T_DEMO().GetDataTable(strCol, orderDirect);
        this.gvResult.DataBind();
    }
    #endregion

}
